<template>
    <el-card class="box-card" width="100%">
  <div slot="header" class="clearfix">
    <span>AI应用详情</span>
    <el-button style="float: right; padding: 1px 0; height: 35px; width: 55px" type="primary" @click="goBack()">返回</el-button>
  </div>
  <div class="forms">
    <el-form ref="detailData" :rules="rules" :model="detailData" label-width="100px" class="app-form">
      <el-form-item label="应用id:" prop="id">
        <el-input v-model="detailData.id" disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="名称：" prop="name">
        <el-input v-model="detailData.name" disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="训练任务id：" prop="train_job_id">
        <el-input v-model="detailData.train_job_id" style="width: 80%" disabled="true"></el-input>
        <el-button type="primary" style="float: right" @click="showTrainjobDetail(detailData.train_job_id)">查看训练任务</el-button>
      </el-form-item>
      <el-form-item label="URL：" prop="url">
        <el-input v-model="detailData.url" disabled="true" ></el-input>
      </el-form-item>
      <el-form-item label="当前状态：" prop="status">
        <el-input v-model="detailData.status" disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="开始时间：" prop="datetime_started">
        <el-input v-model="detailData.datetime_started" disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="结束时间：" prop="datetime_stopped">
        <el-input v-model="detailData.datetime_stopped" disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="描述：" prop="description">
        <el-input v-model="detailData.description" type="textarea" :rows="5" maxlength=500></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="editAppProcess()">保存编辑</el-button>
      </el-form-item>
    </el-form>
  </div>
</el-card>
</template>
<style scoped>
  .forms {
    font-size: 16px;
    text-align: left;
    margin-left: 1px;
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 100%;
  }

  .el-card__header {
    padding: 18px 20px;
    background-color: rgb(238, 241, 246);
  }

  .app-form {
    width: 90%;
    margin: 10px; /* 上下间距160px，左右自动居中*/
    background-color: rgb(255, 255, 255, 0.8); /* 透明背景色 */
    padding: 10px;
    border-radius: 20px; /* 圆角 */
  }
</style>
<script>
import { getApp, editApp } from '@/api/request/application'
export default {
  data () {
    return {
      detailData: null
    }
  },
  methods: {
    update () {
      getApp({app_id: this.$route.query.app_id}).then(response => {
        this.detailData = response
      })
    },
    goBack () {
      this.$router.go(-1)
    },
    editAppProcess () {
      editApp({app_id: this.detailData.id, name: this.detailData.name, description: this.detailData.description}).then(response => {
      })
    },
    showTrainjobDetail (id) {
      this.$router.push({path: '/trainjob/detail', query: {trainjob_id: id}})
    }
  },
  activated () {
    this.update()
  }
}
</script>
